package org.jash.mvp2206.news;

import org.jash.mvp2206.mvp.BasePresenter;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;

public class NewsCategoryPresenter extends BasePresenter<Construct.INewsCategoryView> implements Construct.INewsCategoryPresenter {
    private Construct.INewsCategoryModel model = new NewsCategoryModel();
    @Override
    public void getAllCategories() {
        disposable.add(model.getAllCategories().observeOn(AndroidSchedulers.mainThread())
                .subscribe(r -> {
                    if (isAttach()) {
                        if (r.getCode() == 0) {
                            getWhoView().allCategoriesSuccess(r.getData());
                        } else {
                            throw new RuntimeException(r.getMsg());
                        }
                    }
                }, t -> {
                    if (isAttach()) {
                        getWhoView().failure(t);
                    }
                }));
    }

    @Override
    public void getTopHot() {
        disposable.add(model.getTopHot().observeOn(AndroidSchedulers.mainThread())
                .subscribe(r -> {
                    if (isAttach()) {
                        if (r.getCode() == 0) {
                            getWhoView().topHotSuccess(r.getData());
                        } else {
                            throw new RuntimeException(r.getMsg());
                        }
                    }
                }, t -> {
                    if (isAttach()) {
                        getWhoView().failure(t);
                    }
                }));
    }
}
